package com.shtel.paas.monitorcenter.config.management.warning.contects.web;


import java.util.ArrayList;
import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.shtel.paas.monitorcenter.config.management.warning.contects.entity.MonitorCenterHostInfomationVo;
import com.shtel.paas.monitorcenter.config.management.warning.contects.entity.alarmResponseDto;
import com.shtel.paas.monitorcenter.config.management.warning.contects.entity.alarmResponseEntity;
import com.shtel.paas.monitorcenter.config.management.warning.contects.service.IWarningContectsService;
import com.shtel.paas.monitorcenter.view.dispaly.host.monitor.vo.selecthostMonitorTreeDataVo;
import com.shtel.paas.sdk.core.RefreshableRestController;
import com.shtel.paas.sdk.core.mybatis.EnablePaasMybatis;

@EnablePaasMybatis
@MapperScan("com.shtel.paas.monitorcenter.config.management.warning.contects.mapper")
// mybatis存储库类的包路径
@RefreshableRestController
public class warningConytectsController  {

	@Autowired
	IWarningContectsService service;

	
	@GetMapping("/getContectsInfo")
	public PageInfo<alarmResponseEntity> getContectsInfo(@RequestParam("ip") String ip,
			@RequestParam("page") Integer page,
			@RequestParam("pageSize") Integer pageSize){

		if(ip.equals("")){
			ip=null;
		}
		
		
		
		//Page<alarmResponseEntity> pageContent = Page.build(selectInfo);
		return service.selectAll(ip,page,pageSize);
		
	}
	
	@GetMapping("/updateContectsInfo")
	public int updateContectsInfo(@RequestParam("ip") String ip,
	@RequestParam("dangercontact") String dangercontact,
	@RequestParam("dangercontype") Integer dangercontype,
	@RequestParam("dangeremail") String dangeremail,
	@RequestParam("dangerphone") String dangerphone,
	@RequestParam("id") String id,
	@RequestParam("seriouscontact")String seriouscontact,
	@RequestParam("seriouscontype")Integer seriouscontype,
	@RequestParam("seriousemail")String seriousemail,
	@RequestParam("seriousphone")String seriousphone,
	@RequestParam("warncontact")String warncontact,
	@RequestParam("warncontype")Integer warncontype,
	@RequestParam("warnemail")String warnemail,
	@RequestParam("warnphone")String warnphone){
		alarmResponseDto dto =new alarmResponseDto();
		dto.setDangercontact(dangercontact);
		dto.setDangercontype(dangercontype);
		dto.setDangeremail(dangeremail);
		dto.setDangerphone(dangerphone);
		dto.setId(id);
		dto.setSeriouscontact(seriouscontact);
		dto.setIp(ip);
		dto.setSeriouscontype(seriouscontype);
		dto.setSeriousemail(seriousemail);
		dto.setSeriousphone(seriousphone);
		dto.setWarncontact(warncontact);
		dto.setWarncontype(warncontype);
		dto.setWarnemail(warnemail);
		dto.setWarnphone(warnphone);
		
		return service.updateWarningConytects(dto);
	}
	
	@GetMapping("/deleteContectsInfo")
	public int deleteContectsInfo(@RequestParam("id") String id){
		return service.deleteWarningContects(id);
	}
	
	@GetMapping("/insertContectsInfo")
	public int insertContectsInfo(@RequestParam("ip") String ip,
	@RequestParam("dangercontact") String dangercontact,
	@RequestParam("dangercontype") Integer dangercontype,
	@RequestParam("dangeremail") String dangeremail,
	@RequestParam("dangerphone") String dangerphone,
	@RequestParam("seriouscontact")String seriouscontact,
	@RequestParam("seriouscontype")Integer seriouscontype,
	@RequestParam("seriousemail")String seriousemail,
	@RequestParam("seriousphone")String seriousphone,
	@RequestParam("warncontact")String warncontact,
	@RequestParam("warncontype")Integer warncontype,
	@RequestParam("warnemail")String warnemail,
	@RequestParam("warnphone")String warnphone){
		alarmResponseDto dto =new alarmResponseDto();
		dto.setDangercontact(dangercontact);
		dto.setDangercontype(dangercontype);
		dto.setDangeremail(dangeremail);
		dto.setDangerphone(dangerphone);
		dto.setSeriouscontact(seriouscontact);
		dto.setIp(ip);
		dto.setSeriouscontype(seriouscontype);
		dto.setSeriousemail(seriousemail);
		dto.setSeriousphone(seriousphone);
		dto.setWarncontact(warncontact);
		dto.setWarncontype(warncontype);
		dto.setWarnemail(warnemail);
		dto.setWarnphone(warnphone);
		
		return service.insertWarningContects(dto);
		
	}
	
	
	@GetMapping("/selectIps")
	public List<String> selectIps(){
		return service.selectIpList();
	}
	
	/**
	 * 查询未配置IP地址和systemName
	 * @param: 
	 * @author: zhangyy
	 * @Date:   2018.05.15
	 */
	@GetMapping("/selectIpsAndSystemName")
	public List<MonitorCenterHostInfomationVo> selectIpsAndSystemName(){
		return service.selectIpsAndSystemName();
	}
	
	
	/**
	 * 列表IP地址查询
	 * @param: 
	 * @author: zhongzhaochuan
	 * @Date:   2018.05.26
	 */
	@GetMapping("/getIpTreeData")
	public List<Object> selecthostMonitorTreeData() {
		
		List<Object> resultArray = new ArrayList<>();
		resultArray = service.getIpTreeData();
		return resultArray;
	}
	
	/**
	 * 异步获取动态树的第三层节点数据
	 * @param: 
	 * @author: zhongzhaochuan
	 * @return resultArray
	 */
	@GetMapping("/asyncGetIpTreeData")
	public List<selecthostMonitorTreeDataVo> asyncSelectHostMonitorTreeData(@RequestParam("commentId") String commentId,@RequestParam("hostId") String hostId) {
		
		List<selecthostMonitorTreeDataVo> resultArray = new ArrayList<>();
		resultArray = service.asyncGetIpTreeData(commentId,hostId);
		return resultArray;
	}
}

